﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.city;

namespace Trans.depart
{
    public partial class Add_depart : Form
    {
        DataRowView row;
        public Add_depart()
        {
            InitializeComponent();
        }

        private void Add_depart_Load(object sender, EventArgs e)
        {
            row=(DataRowView)tbdepartBindingSource.AddNew();
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            try
            {
                tbdepartBindingSource.EndEdit();
                tb_departTableAdapter.Update(dataSet.tb_depart);
                this.Close(); 
                MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } 
            
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbdepartBindingSource.CancelEdit();
            this.Close();
        }

        private void bt_city_Click(object sender, EventArgs e)
        {
            select_city f = new select_city();
            f.ShowDialog();
            if(f.HasSelected)
            {
                lb_city.Text = f.Name_s;
                row["city_id"] = f.Id;
            }
        }

        private void tx_code_TextChanged(object sender, EventArgs e)
        {

        }

        private void tx_post_Validating(object sender, CancelEventArgs e)
        {
            if(tx_post.Text.Length>0)
            {
                error.SetError(tx_post, "");
            }
            else
            {
                error.SetError(tx_post, "请输入邮编");
            }
        }

        private void tx_name_Validating(object sender, CancelEventArgs e)
        {
            if(tx_name.Text.Length>0)
            {
                error.SetError(tx_name, "");
            }
            else
            {
                error.SetError(tx_name, "请输入名称");
            }
        }

        private void lb_city_Validating(object sender, CancelEventArgs e)
        {
            if(lb_city.Text.Length>0)
            {
                error.SetError(lb_city, "");
            }
            else
            {
                error.SetError(lb_city, "请选择所在城市");
            }
        }
    }
}
